import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:social_module/viewmodel/list_provider.dart';

class SocialAddPage extends StatefulWidget {
  const SocialAddPage({Key? key}) : super(key: key);

  @override
  _SocialAddPageState createState() => _SocialAddPageState();
}

class _SocialAddPageState extends State<SocialAddPage> {
  TextEditingController _controller = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Color.fromARGB(255, 80, 196, 211),
        title: Text("写心得"),
        centerTitle: true,
        actions: [
          IconButton(
              icon: Icon(Icons.check),
              onPressed: () {
                DateTime date = DateTime.now();
                String dateString =
                    DateFormat("yyyy-MM-dd HH:mm:ss").format(date).toString();
                String comment = _controller.text;
                context
                    .read<ListProvider>()
                    .addToList("1", dateString, comment);
                Navigator.pop(context);
              })
        ],
      ),
      body: Container(
        padding: EdgeInsets.all(5.0),
        child: Column(
          mainAxisSize: MainAxisSize.max,
          children: [
            Expanded(
              child: TextField(
                controller: _controller,
                maxLines: 12,
                decoration: InputDecoration(
                  hintText: "快来分享今日学习心得吧~",
                  border: OutlineInputBorder(),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
